package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.MConfVipPO;
import com.yiyuan.app.mapper.MConfVipMapper;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public class MConfVipDAO extends BaseDAO<MConfVipMapper, MConfVipPO> {

    public MConfVipPO checkVipNext(BigDecimal newRechargeMoney) {
        LambdaQueryWrapper<MConfVipPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.le(MConfVipPO::getThreshold, newRechargeMoney);
        queryWrapper.orderByDesc(MConfVipPO::getVipLevel);
        queryWrapper.last("limit 0,1");
        return getBaseMapper().selectOne(queryWrapper);
    }

    public List<MConfVipPO> findConfigBetweenVips(Integer currentVip, Integer nextVip) {
        LambdaQueryWrapper<MConfVipPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(MConfVipPO::getVipLevel, currentVip);
        queryWrapper.le(MConfVipPO::getVipLevel, nextVip);
        return getBaseMapper().selectList(queryWrapper);
    }
}
